﻿using System;
using System.Text;
using System.Web;
using System.Net.Mail;

/// <summary>
/// 错误发送类,及邮件发送系统;
/// </summary>
/// 
namespace QzEbook.Common
{
    public static class Utilities
    {
        static Utilities()
        {
        }

        /// <summary>
        /// 直接发送邮件;
        /// </summary>
        /// <param name="from">发送方</param>
        /// <param name="to">接收方</param>
        /// <param name="subject">标题</param>
        /// <param name="body">内容</param>
        public static void sendMail(string from, string to, string subject, string body)
        {
            /*SmtpClient mailClient = new SmtpClient(EbookShopConfiguration.MainServer);
            MailMessage mailMessage = new MailMessage(from, to, subject, body);
            mailClient.Send(mailMessage);*/
        }

        public static void output(string msg)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("错误:原因如下<p>{0}</p>", msg);
            HttpContext.Current.Response.Write(sb.ToString());
        }

        /// <summary>
        ///  输出错误,并把错误于email形式发送给管理员;
        /// </summary>
        /// <param name="ex"></param>
        public static void LogError(Exception ex)
        {
            //string dataTime=DateTime.Now.ToLongDateString()+",at"+DateTime.Now.ToShortDateString();
            //string errorMessage = "Exception generated on " + dataTime;

            //System.Web.HttpContext context = System.Web.HttpContext.Current;
            //errorMessage += "\n\n Page Location: " + context.Request.RawUrl;
            //errorMessage += "\n\n Message:" + ex.Message;
            //errorMessage += "\n\n source:" + ex.Source;
            //errorMessage += "\n\n Method" + ex.TargetSite;
            //errorMessage += "\n\n Stack Trace:\n\n" + ex.StackTrace;
            //if (EbookShopConfiguration.EnableErrorLogEmail)
            //{
            //    string from="crl@163.com";
            //    string to = EbookShopConfiguration.ErrorLogEmail;
            //    string subject = EbookShopConfiguration.SiteName + " error report";
            //    string body = errorMessage;
            //    sendMail(from, to, subject, body);
            //}

        }
    }
}